import cv2
import numpy as np

# 读取图片
img = cv2.imread('card.png')

# 二值化
ret, thresh = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)

# 核
kernel = np.ones((3, 3), np.uint8)
# 开运算
opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)

# 显示结果
cv2.imshow('Original', img)
cv2.imshow('Eroded', opening)
cv2.waitKey(0)
cv2.destroyAllWindows()
